const KoaRouter = require('@koa/router')
const { verifyAuthorization } = require('../middleware/login.middleware')
const {
	verifyClub,
	verifyLeaderName,
	verifyClubNameUnique
} = require('../middleware/club.middleware')
const clubController = require('../controller/club.controller')
const { verifyAdmin } = require('../middleware/permission.middleware')

const clubRouter = new KoaRouter({ prefix: '/clubs' })

// userRouter.post('/register', verifyUser, handlePassword, userController.create)
// 1.创建社团
clubRouter.post(
	'/',
	verifyAuthorization,
	verifyClub,
	verifyLeaderName,
	clubController.create
)

clubRouter.get('/clubname', clubController.findOneByName)
// 2.获取所有社团
clubRouter.get('/', clubController.list)
// 3.后去单个社团
clubRouter.get('/:id', clubController.findOne)

// 3.删除一个社团
clubRouter.delete(
	'/:club_id',
	verifyAuthorization,
	clubController.delete
)

// 4.更新一个社团
clubRouter.put(
	'/:club_id',
	verifyAuthorization,
	verifyClubNameUnique,
	verifyLeaderName,
	verifyAdmin,
	clubController.update
)
// 5.修改社团状态
clubRouter.put(
	'/:club_id/status',
	verifyAuthorization,
	verifyAdmin,
	clubController.updateClubStatus
)

// 5.根据社团ID获取社团成员列表
clubRouter.get('/:club_id/members', clubController.getMembers)

// 6.用户申请加入社团
clubRouter.post('/:club_id/join', verifyAuthorization, clubController.join)

// 7.审核社团成员
clubRouter.put(
	'/:club_id/members/:user_id/review',
	verifyAuthorization,
	verifyAdmin,
	clubController.reviewMember
)

// 8.获取全部社团员工
clubRouter.get(
	'/:club_id/members/all',
	clubController.getPendingMembers
)

// 12.根据社长id查找社团
clubRouter.get(
	'/leader/club',
	verifyAuthorization,
	clubController.queryClubByUserId
)

// 9.获取已审核的社团成员列表
clubRouter.get(
	'/:club_id/members/reviewed',
	verifyAuthorization,
	verifyAdmin,
	clubController.getReviewedMembers
)
// 10.根据用户id获取用户参加了的社团
clubRouter.get('/me/:id', verifyAuthorization, clubController.getClubsForUser)

// 11.删除社团团员
clubRouter.delete(
	'/:club_id/members/:user_id/remove',
	verifyAuthorization,
	verifyAdmin,
	clubController.deleteClubMember
)

// 12.退出社团
clubRouter.delete(
	'/:club_id/members/quit',
	verifyAuthorization,
	clubController.quitClub
)

// 13.根据个人id查询加入此社团的状态
clubRouter.get(
	'/:club_id/members/status',
	verifyAuthorization,
	clubController.queryStatusById
)

//14.查询社团人数
clubRouter.get('/join/count', clubController.queryJoinCount)

module.exports = clubRouter
